package com.pts.servlet;


import com.pts.dao.Dao;
import com.pts.dao.UserDao;
import com.pts.vo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;


//管理员登录
@WebServlet(value = "/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        response.setContentType("text/html;charset=utf-8");
        User user = new User();
        user.setName(request.getParameter("name"));
        user.setPwd(request.getParameter("pwd"));
        Dao dao = new UserDao();
        boolean  flag = dao.isExist(user);

        if(flag){
            HttpSession session = request.getSession();
            session.setAttribute("loginname",user.getName());
            request.setAttribute("username",user.getName() );
            request.getRequestDispatcher("admin/welcome.jsp").forward(request,response);
        }else {
            response.sendRedirect("login.html");
        }
    }
}